﻿//-----------------------------------------------------------------------
// <copyright file="TopicFormatter.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 

namespace ChatBox.UI.MessageDisplay
{
    using System.Windows;
    using System.Windows.Documents;

    using ChatBox.Interfaces;
    using ChatBox.XamlUtility;

    /// <summary>
    /// Format the topic 
    /// </summary>
    public class TopicFormatter
    {
        #region data

        /// <summary>
        /// The HyperlinkContext for setting up links
        /// </summary>
        private readonly HyperlinkContext hyperlinkContext;

        /// <summary>
        /// the error log
        /// </summary>
        private readonly ILogger logger;

        #endregion

        #region constructor

        /// <summary>
        /// Initializes a new instance of the TopicFormatter class
        /// </summary>
        /// <param name="hyperlinkContext">the hyperlink Context</param>
        /// <param name="logger">the error log</param>
        public TopicFormatter(HyperlinkContext hyperlinkContext, ILogger logger)
        {
            this.hyperlinkContext = hyperlinkContext;
            this.logger = logger;
        }

        #endregion

        /// <summary>
        /// Generate a tropic document
        /// </summary>
        /// <param name="topic">the topic text</param>
        /// <param name="formatOptions">formatting options</param>
        /// <returns>the result document</returns>
        public FlowDocument GenerateTopicDocument(string topic, FormatOptions formatOptions)
        {
            FlowDocument resultDocument = new FlowDocument();
            resultDocument.PagePadding = new Thickness(2);
            Paragraph contentPara = new Paragraph();
            contentPara.FontSize = formatOptions.FontSize;

            HtmlToXamlConverter converter = new HtmlToXamlConverter(topic, this.hyperlinkContext, this.logger, null);
            contentPara.Inlines.Add(converter.XamlContent);

            resultDocument.Blocks.Add(contentPara);
            return resultDocument;
        }
    }
}
